package com.bhh.myservlet.servlet;

import com.bhh.myservlet.HttpStatus;
import com.bhh.myservlet.Util;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

/**
 * @author bhh
 * @description TODO
 * @date Created in 2021-04-15 16:43
 * @modified By
 */
@Slf4j
public class TimeServlet implements Servlet {
    @Override
    public void init(ServletConfig config) throws ServletException {
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        PrintWriter writer = res.getWriter();
        writer.println(Util.renderStatus(HttpStatus.RE_OK));
        writer.println("Time now is : ");
        writer.println(LocalDateTime.now().toString());
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {
    }
}
